<template>
  <div class="login-container">
    <el-form
      ref="loginForm"
      :model="loginForm"
      :rules="rules"
      class="login-form"
      autocomplete="on"
      label-position="left"
    >
      <div class="title-container">
        <h3 class="title">找回密码</h3>
        <el-steps style="width:480px" :active="2" finish-status="success">
          <el-step title="验证信息"></el-step>
          <el-step title="修改密码"></el-step>
          <el-step title="找回成功"></el-step>
        </el-steps>
      </div>
         <el-tooltip style="margin-top:30px" v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
        <el-form-item prop="password">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            :key="passwordType"
            ref="password"
            v-model="loginForm.password"
            :type="passwordType"
            placeholder="密码"
            name="password"
            tabindex="5"
            @keyup.native="checkCapslock"
            @blur="capsTooltip = false"
          />
          <span class="show-pwd" @click="showPwd">
            <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
      </el-tooltip>
      <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
        <el-form-item prop="password1">
          <span class="svg-container">
            <svg-icon icon-class="password" />
          </span>
          <el-input
            :key="passwordType1"
            ref="password1"
            v-model="password1"
            :type="passwordType1"
            placeholder="确认密码"
            name="password1"
            tabindex="6"
            @keyup.native="checkCapslock"
            @blur="capsTooltip = false"
          />
          <span class="show-pwd" @click="showPwd1">
            <svg-icon :icon-class="passwordType1 === 'password' ? 'eye' : 'eye-open'" />
          </span>
        </el-form-item>
      </el-tooltip>
          
      <el-button
        :loading="loading"
        type="primary"
        style="width:100%;margin-bottom:30px;"
        @click="handleRegist"
      >下一步
      </el-button>
    </el-form>
  </div>
</template>

<script>
// eslint-disable-next-line 
/* eslint-disable */
import Cookies from 'js-cookie'
import { updatePasswordUser1 } from '../../api/user'
export default {
  name: 'Regist',
  data() {
    const validatePassword = (rule, value, callback) => {
      ////console.log(value)
      if (value === '') {
        callback(new Error('密码不能为空'))
      } else {
        callback()
      }
    }
    const validatePassword1 = (rule, value, callback) => {
      ////console.log(this.password1)
       if (this.password1 === '') {
              callback(new Error('请再次输入密码'));
          } else if (this.password1 !== this.loginForm.password) {
              callback(new Error('两次输入密码不一致!'));
          } else {
              callback();
          }     
    }
    
    return {
      loginForm: {
        password:'',
        username:''
      },
      password1: '',
      show: true,
        count:'',
        timer: null,
      rules: {
        password: [{ required: true, trigger: 'blur', validator: validatePassword },
        { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }],
        password1: [{ required: true, trigger: 'blur', validator: validatePassword1 },
        { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' },]
      },
      passwordType: 'password',
      passwordType1: 'password',
      capsTooltip: false,
      loading: false,
      showDialog: false,
      redirect: undefined,
      otherQuery: {}
    }
  },
  mounted() {
    let usernameinfo=Cookies.get('passwordUsername')
    this.loginForm.username = usernameinfo
    ////console.log(this.loginForm.username)
  },
  methods: {
    checkCapslock({ shiftKey, key } = {}) {
      ////console.log(shiftKey, key)
      if (key && key.length === 1) {
        if ((shiftKey && (key >= 'A' && key <= 'Z')) || (!shiftKey && (key >= 'A' && key <= 'Z'))) {
          this.capsTooltip = true
        } else {
          this.capsTooltip = false
        }
      } else {
        this.capsTooltip = false
      }
      if (key === 'CapsLock' && this.capsTooltip === true) {
        this.capsTooltip = false
      }
    },
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    showPwd1() {
      if (this.passwordType1 === 'password') {
        this.passwordType1 = ''
      } else {
        this.passwordType1 = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password1.focus()
      })
    },
    handleRegist() {
          //this.loading = true
          ////console.log(this.loginForm.username)
          const onSuccess = (response) => {
          const { msg } = response
          this.$notify({
            title: '操作成功',
            message: msg,
            type: 'success',
            duration: 2000
          })
          this.loading = false
          }
      if (!this.loading) {
        this.loading = true
        
        //this.postForm.enroll_img=JSON.stringify(this.fileList_enroll)
        ////console.log(this.fileList_enroll)
        this.$refs.loginForm.validate((valid, fields) => {
          ////console.log(valid, fields)
          if (valid) {
            //this.loginForm.role="user"
            const user = Object.assign({}, this.loginForm)
            ////console.log(enroll)
              updatePasswordUser1(user).then(response => {
                onSuccess(response)
                this.$router.push('/login')
              }).catch(() => {
                this.loading = false
              })

          } else {
            const message = fields[Object.keys(fields)[0]][0].message
            this.$message({ message, type: 'error' })
            this.loading = false
          }
        })
      }
    }
  }
}
</script>

<style lang="scss">
  /* 修复input 背景不协调 和光标变色 */
  /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

  $bg: #383443;
  $light_gray: #fff;
  $cursor: #fff;

  @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
    .login-container .el-input input {
      color: $cursor;
    }
  }

  /* reset element-ui css */
  .login-container {
    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;

      input {
        background: transparent;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 12px 5px 12px 15px;
        color: $light_gray;
        height: 47px;
        caret-color: $cursor;

        &:-webkit-autofill {
          box-shadow: 0 0 0px 1000px $bg inset !important;
          -webkit-text-fill-color: $cursor !important;
        }
      }
    }

    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
  }
</style>

<style lang="scss" scoped>
  $bg: #2d3a4b;
  $dark_gray: #889aa4;
  $light_gray: #eee;

  .login-container {
    min-height: 100%;
    width: 100%;
    background-color: $bg;
    overflow: hidden;

    .login-form {
      position: relative;
      width: 520px;
      max-width: 100%;
      padding: 160px 35px 0;
      margin: 0 auto;
      overflow: hidden;
    }

    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;

      span {
        &:first-of-type {
          margin-right: 16px;
        }
      }
    }

    .svg-container {
      padding: 6px 5px 6px 15px;
      color: $dark_gray;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
    }

    .title-container {
      position: relative;

      .title {
        font-size: 26px;
        color: $light_gray;
        margin: 0px auto 40px auto;
        text-align: center;
        font-weight: bold;
      }
    }

    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }

    .thirdparty-button {
      position: absolute;
      right: 0;
      bottom: 6px;
    }

    @media only screen and (max-width: 470px) {
      .thirdparty-button {
        display: none;
      }
    }
  }
</style>
